# coding=utf-8
import logging
from django.shortcuts import render
from django.http import HttpResponse
from authentication import models
from django.shortcuts import RequestContext
from django.shortcuts import render_to_response

logger = logging.getLogger(__name__)

def index(request, *args, **kwargs):
    id = request.session.get('uid', None)
    try:
        user = models.User.objects.get(id=id)
    except:
        user = models.User.objects.none()
    return render_to_response('authentication/index.html', 
        {'user': user}, 
        context_instance=RequestContext(request))


    logger.debug('first debug')
    logger.warning('first debug')
    return HttpResponse('authentication')

def login(request, *args, **kwargs):
    pass

def logout(request, *args, **kwargs):
    pass

def add(request, *args, **kwargs):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            obj = form.save()
            return render_to_response(
                'authentication/success.html', 
                {'obj': obj},
                context_instance=RequestContext(request)
            )

def delete(request, *args, **kwargs):
    pass

def edit(request, *args, **kwargs):
    pass

def leest(request, *args, **kwargs):
    pass